package com.huawei.codearts.tools.utils;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class RedissonUtils {

    private final static String HOST = SettingUtils.getProperty("redis.host");
    private final static int PORT = Integer.parseInt(SettingUtils.getProperty("redis.port"));
    private final static int TIMEOUT = Integer.parseInt(SettingUtils.getProperty("redis.timeout"));
    private final static String AUTH = SettingUtils.getProperty("redis.auth");
    private final static int SELECT = Integer.parseInt(SettingUtils.getProperty("redis.select"));

    //获取jedis对象
    public static RedissonClient getRedisson() {
        String redisAddress = String.format("redis://%s:%s", HOST, PORT);
        Config config = new Config();
        config.useSingleServer().setAddress(redisAddress);
        if (!AUTH.isEmpty()) {
            config.useSingleServer().setPassword(AUTH);
        }
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
